package cn.jhc.social.qq.connect;

import org.springframework.social.oauth2.OAuth2Template;
import org.springframework.web.client.RestTemplate;

import cn.jhc.social.qq.api.impl.HTMLFormMapHttpMessageConverter;

public class QQOAuth2Template extends OAuth2Template {

	public QQOAuth2Template(String clientId, String clientSecret) {
		super(clientId, clientSecret, 
				"https://graph.qq.com/oauth2.0/authorize",
				"https://graph.qq.com/oauth2.0/token");
		//appId and appSecret should be in parameters
		setUseParametersForClientAuthentication(true);
	}

	@Override
	protected RestTemplate createRestTemplate() {
		RestTemplate restTemplate = super.createRestTemplate();
		//数据是form-urlencoded，但类型是text/html.
		restTemplate.getMessageConverters().add(new HTMLFormMapHttpMessageConverter());
		return restTemplate;
	}
}
